﻿using Tfs.OnTheRoad.Commands;
using Tfs.OnTheRoad.Model;
namespace Tfs.OnTheRoad.ViewModel
{
    /// <summary>
    /// Changesets ViewModel
    /// </summary>
    public class ChangesetListViewModel : BaseListViewModel<Changeset>
    {
        public NavigateToChangesetCommand NavigateToChangeset
        {
            get;
            private set;
        }

        private Project _currentProject;

        public Project CurrentProject
        {
            get { return _currentProject; }
            set { _currentProject = value; }
        }

        private Build _currentBuild;
        public Build CurrentBuild
        {
            get { return _currentBuild; }
            set { _currentBuild = value; }
        }


        private Branch _currentBranch;
        public Branch CurrentBranch
        {
            get { return _currentBranch; }
            set { _currentBranch = value; }
        }

        public ChangesetListViewModel(Model.Branch branch)
            : base()
        {
            NavigateToChangeset = new NavigateToChangesetCommand();
            _currentBranch = branch;
            PageTitle = "Changesets";
            OrderBy = "CreationDate desc";
            _entityCollectionName = string.Format("Branches('{0}')/Changesets",_currentBranch.Path);
        }

        public ChangesetListViewModel(Model.Build build)
            : base()
        {
            NavigateToChangeset = new NavigateToChangesetCommand();
            _currentBuild = build;
            PageTitle = "Changesets";
            OrderBy = "CreationDate desc";
            _entityCollectionName = string.Format("Builds(Project='{0}',Definition='{1}',Number='{2}')/Changesets", _currentBuild.Project, _currentBuild.Definition, _currentBuild.Number);
        }

        public ChangesetListViewModel(Model.Project project)
            : base()
        {
            NavigateToChangeset = new NavigateToChangesetCommand();
            _currentProject = project;
            PageTitle = "Changesets";
            OrderBy = "CreationDate desc";
            _entityCollectionName = string.Format("Projects('{0}')/Changesets", _currentProject.Name);
        }

        public ChangesetListViewModel(string path)
            : base(path)
        {
        }

        public override string GetNoResultsFoundMessage()
        {
            return "No changesets were found.";
        }

        private string _entityCollectionName;

        internal string EntityCollectionName
        {
            get { return _entityCollectionName; }
            set { _entityCollectionName = value; }
        }
        
        public override string GetEntityCollectionName()
        {
            return _entityCollectionName;
        }
    }
}
